﻿using System;
using System.Collections;
using System.Collections.Generic;
//using IBatisNet.DataAccess;
using Wsitech.Model;

namespace Wsitech.BLL
{
    /// <summary>
    /// 功能：     Keyword业务逻辑实现
    /// 作者：     LI
    /// 日期：     5/16/2012
    /// </summary>
    public class KeywordBLL
    {
        private Wsitech.Persistence.Interface.IKeywordDao dao = null;

        private KeywordBLL()
        {
            dao = Wsitech.Persistence.Dao.KeywordSqlMapDao.Instance;
        }

        #region （懒汉）单例模式
        private static KeywordBLL instance = null;
        private static object syncRoot = new object();
        public static KeywordBLL Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new KeywordBLL();
                        }
                    }
                }
                return instance;
            }
        }
        #endregion


        #region	基本功能 不能修改


        /// <summary>
        /// 根据主键得到明细
        /// </summary>
        /// <returns></returns>
        public Keyword GetDetail(System.String keyid)
        {
            try
            {
                return dao.GetDetail(keyid);
            }
            catch
            {
                throw;
            }
        }


        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public IList<Keyword> GetList()
        {
            try
            {
                IList<Keyword> list = dao.GetList();
                return list;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="TopCounts"></param>
        /// <returns></returns>
        private IList<Keyword> GetListByParams(object TopCounts, Keyword keyword)
        {
            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("TopCounts", TopCounts);
                IList<Keyword> list = dao.GetListByParams(ht);
                return list;
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public object Add(Keyword keyword)
        {
            try
            {
                return dao.Add(keyword);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public int Update(Keyword keyword)
        {
            try
            {
                return dao.Update(keyword);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="KeyId"></param>
        /// <returns></returns>
        public int Delete(System.String keyid)
        {
            try
            {
                return dao.Delete(keyid);
            }
            catch
            {
                throw;
            }
        }

        #endregion


        #region 扩展功能

        #endregion


        /// <summary>
        /// 根据关键字内容获取关键字数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public Keyword GetDetailByKey(string key)
        {
            Hashtable ht = new Hashtable();
            ht.Add("key", key);

            IList<Keyword> list = dao.GetListByParams(ht);
            if (list != null && list.Count > 0)
            {
                return list[0];
            }
            else
            {
                return null;
            }

        }

        /// <summary>
        /// 获取某信息的关键字信息列表
        /// </summary>
        /// <param name="textinfoid"></param>
        /// <returns></returns>
        public IList<Keyword> GetListByTextInfoId(string textinfoid)
        {
            return dao.GetListByByTextInfoId(textinfoid);
        }
    }
}
